def isrepeat(s):
    d = s[0]
    for i in s:
        if i != d: return False
    return True

def remove_repeat(s ):
    r = []
    for i in s:
        if not isrepeat(i):r.append(i)
    return r
            

def get_substr(s, n):
    max = len(s) -n + 1
    r = []
    for i in range(max):
        r.append(s[i:(i+n)])
    return remove_repeat(set(r))
    
def test2(s):
    pos = -1
    rc = ''
    for sub in get_substr(s, 2):

        pos = s.find( sub*7 ) 
        #print s, pos
        if pos != -1:
            rc = sub
            break

    return pos, rc


def test3(s):
    pos = -1
    rc = ''
    for sub in get_substr(s, 3):

        pos = s.find( sub*5 ) 
        #print s, pos
        if pos != -1:
            rc = sub
            break

    return pos, sub

if __name__ == '__main__':
    import bsddb
    d = bsddb.btopen('fc_just_seq.bsd', 'r')
    pos = -1

    while True:
        try:
            gi,seq = d.next()
        except KeyError:
            print '\nthe last gi is:', gi, '\n'
            break
        else:
            pos, rc = test2(seq)
            if pos != -1:print '2 ', rc, ' ', gi, pos
            else:
                pos, rc = test3(seq) 
                if pos != -1:print '3 ',rc, ' ',  gi, pos
        

